<?php if(!defined('APP_ROOT')){exit('error!');}?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $site_title;?></title>
<link type="text/css" href="<?php echo PUBLIC_URL;?>css/font-awesome.min.css" rel="stylesheet">
<link type="text/css" href="<?php echo TEMPLATE_URL;?>style.css" rel="stylesheet">
<script type="text/javascript" src="<?php echo PUBLIC_URL;?>js/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo TEMPLATE_URL;?>js/manage.js"></script>
</head>
<body>
<?php include View::getView('header');?>
<?php include View::getView('side');?>
<div id="mainbox">
    <div class="wrapper">
        <div class="main">
            <div class="itembox w100">
                <div class="wrap">
                    <h2><?php echo $page_title;?><span><a href="<?php echo APP_URL;?>record/index"><i class="fa fa-share"></i> 返回我的录入列表</a></span></h2>
                    <div class="itemmain">
                        <div id="adm_record_choose">
                            <form action="" method="get" onsubmit="return checkChooseForm()" name="chooseForm">
                                <select name="s" onchange="shopChoosed(this.value)">
                                    <option value="0">请选择店铺</option>
                                </select>
                                <select name="d">
                                    <option value="0">请先选择店铺</option>
                                </select>
                                <input type="submit" value="开始录入">
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php include View::getView('footer');?>
    </div>
</div>
<script type="text/javascript">
var shopes = <?php echo json_encode($shopes);?>;
$(function(){
    var shopOptions = '<option value="0">请选择店铺</option>';
    shopes.forEach(function(value,index){
        shopOptions += '<option value="'+value.sid+'">'+value.shopname+'</option>';
    });
    $("form[name=chooseForm] select[name=s]").html(shopOptions);
})

function shopChoosed(v){
    var theDitches = [];
    shopes.forEach(function(value,index){
        if(value.sid==v){
            theDitches = value.ditches;
        }
    });

    if(theDitches == undefined){
        var ditchesOption = '<option value="0">请先选择店铺</option>';
    }else{
        var ditchesOption = '<option value="0">请选择渠道</option>';
        theDitches.forEach(function(value,index){
            ditchesOption += '<option value="'+value.did+'">'+value.ditchname+'</option>';
        });
    }
    $("form[name=chooseForm] select[name=d]").html(ditchesOption);
}

function checkChooseForm(){
    var shop_id = $("form[name=chooseForm] select[name=s]").val();
    var ditch_id = $("form[name=chooseForm] select[name=d]").val();
    if(shop_id==0||ditch_id==0){
        alert("请选择正确的店铺和对应的渠道！");
        return false;
    }
    return true;
}
</script>
</body>
</html>